/*
 * @Author: adolphus adolphus520@163.com
 * @Date: 2022-11-17 20:53:58
 * @LastEditors: ${git_name} ${git_email}
 * @LastEditTime: 2025-08-01 11:43:04
 * @Description: file content
 */
import {
  createWebHistory,
  createWebHashHistory,
  createRouter,
} from "vue-router";
import { start, close } from "@/lib/global";
import { store } from "@/store";

const routes = [
  {
    path: "/",
    redirect: "/index.html",
  },
  {
    path: "/index.html",
    name: "试验广场",
    component: () => import("@/views/DataTableView.vue"),
  },
];

const router = createRouter({
  history: createWebHistory(),
  //history: createWebHashHistory(),
  routes,
});

router.beforeEach((to, from, next) => {
  let needLogin = true;
  const token = store.getters.getToken;
  if (token) {
    needLogin = false;
    /*let sigle = this.$axios.post('/uua/authenticated', {}).then(response => {
        let data = response.data.code
        if (1 == data.code) {
            return 1
        } else if (0 != data.code) {
            console.log(data.msg)
        }
        return 0
    }).catch(error => {
        console.log(error)
        return 0
    })
    if (1 == sigle)
        needLogin = true*/
  }
  if (needLogin) {
    window.location.href = "login.html";
  } else {
    // 每次切换页面时，调用进度条
    start();
    // 这个一定要加，没有next()页面不会跳转的。这部分还不清楚的去翻一下官网就明白了
    next();
  }
});

router.afterEach(() => {
  close();
});

export default router;
